﻿using System.Windows;
using System.Windows.Media;

namespace ZOIL.DataBackend.Server
{
    public partial class AddUserDialog : Window
    {
        public AddUserDialog()
        {
            InitializeComponent();
        }

        /// <summary>
        /// the database user that is created when the user clicks the 'Add user' Button
        /// </summary>
        public DatabaseUser User { get; private set; }

        /// <summary>
        /// Event handler for the 'Add User' Button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddUser_Click(object sender, RoutedEventArgs e)
        {
            if (txtUser.Text != "" && txtPass.Text != "")
            {
                User = new DatabaseUser(txtUser.Text, txtPass.Text);
                DialogResult = true;
            }
            else if (txtUser.Text == "" && txtPass.Text == "")
            {
                txtUser.Background = Brushes.Red;
                txtPass.Background = Brushes.Red;
            }
            else if (txtUser.Text == "")
            {
                txtUser.Background = Brushes.Red;
                txtPass.Background = null;
            }
            else
            {
                txtPass.Background = Brushes.Red;
                txtUser.Background = null;
            }
        }

        /// <summary>
        /// Event handler for the 'Cancel' Button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
